<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@include file="/WEB-INF/templates/common/taglib.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>New Document</title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<script language="javascript">
	
</script>
<body>
	<OBJECT ID="ocx" CLASSID="CLSID:49903B72-9F44-41E1-A79B-B85A8BCEB89A">
	</OBJECT>
	<script language="javascript">
		/* var Microsoft_Scan = {
			//扫描信息图片路径数据存放集合
			scanImgArr:[],
			//开启扫描仪
			openScaner : function() {
				var scaner = ocx;
				scaner.DSMode(9);
				var openStatus = scaner.openScanner();
				if (openStatus != 1) {
					var errorCode = scaner.GetErrorCode();
					alert("扫描仪开启失败!错误代码:" + errorCode);
				}
			},
			//扫描配置
			init:function(){
				var scaner = ocx;
				ocx.SetImageName(this.tempImgFile, "0", 1, 7);
				//去钉孔
				ocx.PunchHoleRemoval(1);
				//自动纠偏
				ocx.AutoDeskew(1);
				//黑边补白
				ocx.BlackBorderRemoval(1);// 注释：默认黑边补白
				//文件格式,可以为下面的几个值:
				//	0:bmp
				//	1:jpg
				//	2.单页tif
				//	3.多页tif
				//	4.单页pdf
				//	5.多页pdf
				//	6.可检索的单页pdf，需要支持OCR识别。
				//	7.可检索的多页pdf，需要支持OCR识别。
				ocx.ImageFormat = 1;
				// 扫描仪类型
				//0 Flatbed 平板扫描仪
				//1 ADF  
				//2 ADF duplex 
				ocx.ScanSourceType = 1;
			},
			//关闭扫描仪
			closeScaner : function() {
				var scaner = ocx;
				scaner.CancelXfers();
				var closeStatus = scaner.CloseScanner();
				if (closeStatus != 1) {
					var errorCode = scaner.GetErrorCode();
					alert("扫描仪关闭失败!错误代码:" + errorCode);
				}
			},
			//设置扫描仪
			settingScaner : function() {
				var scaner = ocx;
				scaner.DSMode(9);
				var openStatus = scaner.openScanner();
				scaner.ShowUISettings();
			},
			//单扫
			startScan:function(scanType){
				var scaner = ocx;
				// 单扫
				if(scanType==1){
					scaner.Scan(1,0);
				}else{
					scaner.Scan(-1,0);
				}
				
			},
			//取消扫描
			cancleScan:function(){
				var scaner = ocx;
				scaner.CancelXfers();
			},
			//扫描临时文件生成路径
			tempImgFile:"D://upload/tempImgPath",
			//删除扫描生成临时文件夹内容
			deleteTempImgs:function(){
				var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
				var fileSystem = fileSystemObject.GetFolder(this.tempImgFile);
				var enumFiles = new Enumerator(fileSystem.files);
				for (; !enumFiles.atEnd(); enumFiles.moveNext()){
					enumFiles.item().Delete();
				}
			}
		} */

		// Open();
		function Open() {
			//ocx.SetScan();

			//ocx.LoadLibraryEngine();

			ocx.DSMode(9);
			var pp = ocx.openScanner();
			if (1 == pp) {
				alert("open scanner success");

			} else {
				var Error = ocx.GetErrorCode();
				alert(Error);
			}
		}

		function Scan() {
			//去除空白页	-2：不自动去除空白页。-1：自动去除空白页。
			//ocx.AutoDiscardBlankPages = -1;
			//alert(ocx.GetState()) ;
			//ocx.GetPageNum(0);
			//ocx.ShowUI = 0;
			//ocx.AutoScan = 0;
			var Path= document.getElementById("FilePath").value;
			//var FPrefix= document.getElementById("FilePrefix").value;
			//var nStartIndex=0;
			//var nIndexLength=5;
			//ocx.GetImageName(Path,FPrefix,nStartIndex,nIndexLength);
			//ocx.SetImageName(Path,FPrefix,nStartIndex, 5);
			ocx.SetImageName("E://image", "0", 1, 7);
			//var Resol = document.getElementById("Resolution").value;
			//扫描图像的分辨率DPI,需要根据扫描仪来确定具体值
			//ocx.ScanResolution = Resol;
			//var currSelectIndex = document.getElementById("PicType").selectedIndex;
			/**
			 *  扫描图像的像素属性：
			 *  0  BW1bpp  黑白二值图
			 *  1  Gray8bpp 8位灰度图
			 *  2  RGB24bpp  24 位RGB图
			 *  3  16位灰阶  使用16位灰阶图像格式只能保存成TIF
			 */
			//ocx.ScanPixelType = 2;
			var picTypeEx = document.getElementById("PicTypeEx").selectedIndex;
			//文件格式,可以为下面的几个值:
			//	0:bmp
			//	1:jpg
			//	2.单页tif
			//	3.多页tif
			//	4.单页pdf
			//	5.多页pdf
			//	6.可检索的单页pdf，需要支持OCR识别。
			//	7.可检索的多页pdf，需要支持OCR识别。
			ocx.ImageFormat = 2;
			//var scanTypeIdx = document.getElementById("ScannerType").selectedIndex;
			// 扫描仪类型
			//0 Flatbed 平板扫描仪
			//1 ADF  
			//2 ADF duplex 
			ocx.ScanSourceType = 1;
			//var TiffIdx = document.getElementById("TiffCom").selectedIndex;
			//设置tiff压缩方式
			//0：none
			//1：jpeg压缩（可以设置CompressionRate改变jpeg压缩的Tiff图像的压缩率，只针对GRAY 和RGB图像）
			//2：Group4 FAX 压缩（只针对BW图像）。
			//ocx.TiffCompressType = TiffIdx;
			//var comRate = document.getElementById("CompressRate").value;
			//压缩范围:
			//	设置范围为 1-100
			//针对JPEG，TIFF（JPEG压缩方式）和PDF（JPEG压缩方式）图像格式有效。
			//ocx.CompressionRate = comRate;
			//自动压缩
			//ocx.AutoDeskew = 1;
			
			//var ContVal = document.getElementById("Contrast").value;
			//对比度
			//扫描图像的对比度设置范围为-100-100，默认值为 0
			/* ocx.Contrast = ContVal;
			var bSmooth = document.getElementById("SetSmooth").checked;
			var nStrength = document.getElementById("smoothStrength").selectedIndex;
			var bremoveBG = document.getElementById("removeBG").checked; */
			/* 				if(nStrength == 0)
			 {
			 nStrength = 2;
			 } 
			 if(bSmooth)
			 {
			 ocx.SetBackgroundSmooth(bSmooth, 0,0,0,0,nStrength,bremoveBG);
			 }
			 else
			 {
			 ocx.SetBackgroundSmooth(bSmooth, 0,0,0,0,nStrength,bremoveBG);
			 }  */
			//var isSupportPunchHole = ocx.IsSupportPunchHole()

			//ocx.SetBlackBorderRemoval=1;
			//ocx.getPunchHoleRemoval();

			//ocx.TiffCompressType = 1;
			//去钉孔
			//ocx.PunchHoleRemoval(1);
			//自动纠偏
			//ocx.AutoDeskew(1);
			//黑边补白
			//ocx.BlackBorderRemoval(1);// 注释：默认黑边补白
			if (1 == ocx.Scan(-1, 0)) {

				//var img_count = ocx.GetScanImageCount();
				//alert("扫描成功,共计" + img_count + "张");
			 ocx.CloseScanner();
			}
		}

		function Close() {

			//ocx.SetClearSmartCalibrationData();

			/*var nVal;
			nVal=ocx.GetBlankPageFideSensitivity();
			alert(nVal);
			ocx.SetBlankPageFindSensitivity(1);*/

			if (1 == ocx.CloseScanner()) {
				alert("close scanner");
			}
			//ocx.FreeLibraryEngine();
		}

		function OCR() {
			var nVal = 0;
			nVal = ocx.RecognizeFile("d:\\aaa.jpg", "C:\\Temp.txt", 0, 0,
					"0,0,0,0", 1);
			alert(nVal);
			//nVal=ocx.RecognizeForMulitiFile("E:\\Image",0,"E:\\Image\\Test.PDF",13,64);
			//var sVal;
			//sVal=ocx.RecognizeFileEx("D:\\aaaa.jpg",0,0,"0,0,0,0",1,1);
			//alert(sVal);
		}

		function BarCode() {

			//ocx.UpImageFileEx("172.17.7.204",8080,"/aaa","D:\\Test.jpg");
			var sVal = "";
			sVal = ocx.GetBarcodeEx1("D:\\Test1.jpg", 0, 0, 0, 0);
			alert(sVal);
			//ocx.ImageToWord("D:\\imageTest","D:\\imageTest\\Test.doc","jpg");	
		}
		function Rotation() {
			var AngleValue = document.getElementById("Angle").value;
			if (0 == AngleValue) {
				return;
			}
			var nRet = ocx.RotationImage(AngleValue);
		}

		function SettingScanner() {
			ocx.DSMode(9);
			var pp = ocx.openScanner();
			ocx.ShowUISettings();
		}
		
		function deleteTempImgs(){
			var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
			var fileSystem = fileSystemObject.GetFolder("E:\image");
			var enumFiles = new Enumerator(fileSystem.files);
			for (; !enumFiles.atEnd(); enumFiles.moveNext()){
				enumFiles.item().Delete();
			}
		}
	</script>
	<script LANGUAGE=Javascript FOR="ocx"
		EVENT="PostScanEveryPage(bSuccess)" defer>
		var ImgPathValue;
		var imgpath = "";
		ImgPathValue = ocx.GetCurrentScanImagePath();
		
		alert(ImgPathValue);
		/* Microsoft_Scan.scanImgArr.push(ImgPathValue);
		for(var i=0;i<Microsoft_Scan.scanImgArr.length;i++){
			alert(Microsoft_Scan.scanImgArr[i]);
		} */
	</script>

	<input id=btnOpen type="button" value=OpenScanner onclick="Open()">
	<input id=btnScan type="button" value=Scan onclick="Scan()">
	<input id=btnClose type="button" value=CloseScanner onclick="Close()">
	<input id=btnClose type="button" value=SettingScanner
		onclick="SettingScanner()">
	<input id=btnOCR type="button" value="删除扫描临时文件"  onclick="deleteTempImgs()">
	<input id=btnOCR type="button" value=OCR onclick="OCR()">
	<input id=btnBarCode type="button" value=BarCode onclick="BarCode()">
	<br>
	<br> 图像路径
	<input id="FilePath" type="text" value="E:\image" /> 图像前缀
	<input id="FilePrefix" type="text" value="abc" /> 分辨率
	<input id="Resolution" type="text" value="200" />
	<br>
	<br> 图标保存类型
	<select id="PicType">
		<option value="0">BW</option>
		<option value="1">GRAY</option>
		<option value="2">RGB</option>
	</select> 扫描仪类型
	<select id="ScannerType">
		<option value="0">平板</option>
		<option value="1">ADF单扫</option>
		<option value="2">ADF双扫</option>
	</select> 图标保存格式
	<select id="PicTypeEx">
		<option value="1">bmp</option>
		<option value="2">jpg</option>
		<option value="3">tif</option>
		<option value="4">multitif</option>
		<option value="5">pdf</option>
		<option value="6">multipdf</option>
		<option value="7">可检索的单页PDF</option>
	</select> Tiff压缩
	<select id="TiffCom">
		<option value="1">NULL</option>
		<option value="2">JPG压缩</option>
		<option value="3">G4压缩</option>
	</select>
	<br>
	<br> 压缩质量
	<input id="CompressRate" type="text" value="20" /> 对比度
	<input id="Contrast" type="text" value="0" />
	<br>
	<br> 使用背景平滑功能
	<input type="checkbox" id="SetSmooth" value="1">
	<br>
	<br> 删除背景
	<input type="checkbox" id="removeBG" value="1">
	<br>
	<br> 平滑强度
	<select id="smoothStrength">
		<option value="1">默认</option>
		<option value="2">低</option>
		<option value="3">中</option>
		<option value="4">高</option>
	</select>

	<input id=btnOpen type="button" value="旋转" onclick="Rotation()">

	旋转角度
	<input id="Angle" type="text" value="0" />
	<br>
	<input id="imgpath" type="text" value="" style="width: 600px;">
	<div id="picshow"></div>

</body>
</html>